package cn.ncupyh;

public class Grades {
    //属性
    private String name;
    private int grade;

    //
    public Grades() {
    }

    public Grades(String name, int grade) {
        this.name = name;
        this.grade = grade;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getGrade() {
        return grade;
    }

    public void setGrade(int grade) {
        this.grade = grade;
    }
//Main
    public static void main(String[] args) {
        //创建对象
      Grades[] stus = new Grades[3];
      Grades g1 = new Grades("小明",70);
      Grades g2 = new Grades("小红",80);
      Grades g3 = new Grades("张三",75);
      //将数据存放到数组里
        stus[0] = g1;
        stus[1] = g2;
        stus[2] = g3;
        //遍历数组获取最高分
        Grades max = stus[0];
        for (int i = 1; i < stus.length; i++) {
            if(stus[i].grade > max.grade){
                max = stus[i];
            }
        }
        System.out.println("本次数学考试" + max.name + "获得最高分");
    }
}
